{% macro render_label(field, nonrequired) %}
    {% if nonrequired %}
        {{ field.label(class_="control-label norequired") }}
    {% else %}
        {{ field.label(class_="control-label") }}
    {% endif %}    
{% endmacro %}

{% macro render_field(field, label_nonrequired) %}
    <div class="form-group">
        {{ render_label(field, label_nonrequired) }}
        {{ field(**kwargs)|safe }}
        {% if field.errors %}
            <div class="text-danger">{{ translate(field.errors[0]) }}</div>
        {% endif %}
    </div>
{% endmacro %}

{% macro render_v_field(field, label_nonrequired) %}
    <div class="form-group" id="ver_con">
        {{ render_label(field, label_nonrequired) }}
        {{ field(**kwargs)|safe }}
        {% if field.errors %}
            <div class="text-danger">{{ translate(field.errors[0]) }}</div>
        {% endif %}
    </div>
{% endmacro %}

{% macro render_phone_field(field, label_nonrequired) %}
    {{ render_field(field, label_nonrequired, pattern="^((\d{3,4}-?)?\d{7,8})|\d{11}|\d{12}$", **kwargs) }}
{% endmacro %}

{% macro render_vcode_field(field, label_nonrequired) %}
    {{ render_v_field(field, label_nonrequired, pattern="^[0-9]{6}$", **kwargs) }}
{% endmacro %}

{% macro render_email_field(field, label_nonrequired) %}
    {{ render_field(field, label_nonrequired, pattern="^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$", **kwargs) }}
{% endmacro %}

{% macro render_select(field, label_nonrequired) %}
<div class="form-group">
    {{ render_label(field, label_nonrequired) }}
    <select class="form-control" name="{{ field.id }}">
        {% for option in field %}
            {{ option }}
        {% endfor %}
     </select>
    {% if field.errors %}
        <div class="text-danger">{{ translate(field.errors[0]) }}</div>
    {% endif %}
</div>
{% endmacro %}

{% macro render_radio(field, label_nonrequired) %}
<div class="form-group">
    {{ render_label(field, label_nonrequired) }}
    {% for sub in field %}
    <label class="radio-inline norequired">
        {{ sub }}
        {{ sub.label(class_="norequired") }}
    </label>
    {% endfor %}
</div>
{% endmacro %}